package com.rural.bus.driver.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rural.bus.driver.R;
import com.rural.bus.driver.model.Order;

/**
 * 通用对话框
 * @author Peanut
 */
public class OrderConfirmDialog extends Dialog implements View.OnClickListener {
    private TextView tv_msg, tv_time, tv_distance;
    private ImageView iv_modify_distance;
    private Button btn_confirm;
    private Button btn_cancel;
    private Order order;
    private OnDialogDismissListener onDialogDismissListner;
    private LinearLayout linearlayout_button_division;
    private String confirm_msg;
    private String cancel_msg;

    public interface OnDialogDismissListener {
        void onConfirmClicked();

        void onCancelClicked();
    }


    public OrderConfirmDialog(Context context, String confirm_msg
            , String cancel_msg
            , Order order, OnDialogDismissListener listner) {
        super(context, R.style.common_alert_dialog);

        this.order = order;
        this.onDialogDismissListner = listner;
        this.confirm_msg = confirm_msg;
        this.cancel_msg = cancel_msg;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_order_confirm_dialog);
        initView();
    }

    private void initView() {
        tv_msg = (TextView) findViewById(R.id.tv_msg);
        btn_confirm = (Button) findViewById(R.id.btn_confirm);
        btn_cancel = (Button) findViewById(R.id.btn_cancel);
        btn_confirm.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
        
    	iv_modify_distance = (ImageView) findViewById(R.id.iv_modify_distance);
		tv_time = (TextView) findViewById(R.id.tv_time);
		tv_distance = (TextView) findViewById(R.id.tv_distance);

        linearlayout_button_division = (LinearLayout) findViewById(R.id.linearlayout_button_division);

        if (confirm_msg == null) {
            btn_confirm.setVisibility(View.GONE);
            linearlayout_button_division.setVisibility(View.GONE);
        } else {
            btn_confirm.setText(confirm_msg);
        }

        if (cancel_msg == null) {
            btn_cancel.setVisibility(View.GONE);
            linearlayout_button_division.setVisibility(View.GONE);
        } else {
            btn_cancel.setText(cancel_msg);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_confirm:
                if (onDialogDismissListner != null) {
                    dismiss();
                    onDialogDismissListner.onConfirmClicked();
                }
                break;
            case R.id.btn_cancel:
                if (onDialogDismissListner != null) {
                    dismiss();
                    onDialogDismissListner.onCancelClicked();
                }
                break;
        }
    }

}
